using System;
using System.Collections;
using System.Runtime.CompilerServices;
using Awaiter;
using ThemeChain;
using jQueryApi;

namespace Nsb.Classes
{
    [IgnoreNamespace]
    public static class CloudMail
    {
        private static string SendUrl
        {
            get { return Uri.Join("http://playnexus.com", ThemeBase.AppUri, "sendmail.php"); }
        }

        public static void SendMailAw(Await awp, Dictionary mail)
        {
            jQueryAjaxOptions options = new jQueryAjaxOptions();
            options.Url = SendUrl;
            options.Data = mail;
            options.DataType = "jsonp";
            options.Type = "POST";

            options.Success =
                delegate(object data, string textStatus, jQueryXmlHttpRequest request)
                {
                    //Inform.Dump(data);
                    awp.Done();
                };

            options.Error =
                delegate(jQueryXmlHttpRequest request, string textStatus, Exception error)
                {
                    Inform.Error("Error sending mail {0} {1}", textStatus, error);
                    awp.Handle(new Exception(Exceptions.SendMailError));
                };

            jQuery.Ajax(options);
        }
    }

    public abstract class SendMailData
    {
        // Required
        public string to;
        public string from;
        public string subject;
        public string content;
        // Optional
        public string textonly;
        public string sendfile;
        public string recipients;
        public bool toAll;
        public bool sendToMeAlso;
    }
}